package com.example.clientmiviamoviego4;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;

/**
 * Activity che gestisce la prima schermata visualizzata dall'app.
 * 
 * @author Gang of Four
 * 
 */
public class SplashActivity extends Activity {

	/**
	 * Intero indicante il tempo di visualizzazione della SplashActivity stessa.
	 * */
	private static int SPLASH_TIME_OUT = 1200;
	/**
	 * Stringa indicante l'URL relativo all'indirizzo IP del server.
	 * */

    //Indirizzo del server da cambiare 
	public String basePath = "http://172.19.16.152:8080/";

	/**
	 * Metodo richiamato quando l'activity viene creata per la prima volta.
	 * */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);

		new Handler().postDelayed(new Runnable() {

			/*
			 * Showing splash screen with a timer. This will be useful when you
			 * want to show case your app logo / company
			 */

			@Override
			public void run() {
				SharedPreferences prefs = PreferenceManager
						.getDefaultSharedPreferences(SplashActivity.this);
				boolean regComplete = prefs.getBoolean("registered", false);
				if (regComplete) {
					Intent intent = new Intent(SplashActivity.this,
							MainActivity.class);
					intent.putExtra("basePath", basePath);
					startActivity(intent);
				} else {
					Intent intent = new Intent(SplashActivity.this,
							RegistrationActivity.class);
					intent.putExtra("basePath", basePath);
					startActivity(intent);
				}

				finish();
			}
		}, SPLASH_TIME_OUT);
	}
}
